<template>
    <el-table :data="orderItemData" :span-method="objectSpanMethod" style="width: 100%">
        <el-table-column prop="oiid" label="详情ID" width="80" />
        <el-table-column prop="oid" label="订单ID" width="100" />
        <el-table-column prop="gid" label="商品ID" width="100" />
        <el-table-column prop="price" label="商品单价" width="120" />
        <el-table-column prop="num" label="商品数量" width="100" />
        <el-table-column prop="createTime" label="创建时间" width="200" />
        <el-table-column prop="updateTime" label="最后一次更新时间" width="200" />
    </el-table>
</template>

<script>
import axios from 'axios'
import { ElMessage } from 'element-plus'

axios.defaults.baseURL = '/api'

export default {
    data() {
        return {
            orderItemData: [
                {
                    "oiid": 1,
                    "oid": 2,
                    "gid": 3,
                    "price": 79.9,
                    "num": 1,
                    "createTime": "2023-12-26T19:03:38",
                    "updateTime": "2023-12-26T19:03:38",
                    "status": 1
                },
            ],
        }
    },
    created() {
        this.getOrderItemData()
    },
    methods: {
        getOrderItemData() {
            axios.get('/orderItem')
                .then(result => {
                    if (result.data.code === 1) {
                        this.orderItemData = result.data.data;
                    }
                })
                .catch(err => {
                    console.log(err);
                })
        },
        objectSpanMethod({ row, rowIndex, columnIndex }) {
            let reArr = [1, 1];
            let len = this.orderItemData.length - 1;
            if (columnIndex === 1) {
                if (rowIndex > 0 && this.orderItemData[rowIndex - 1].oid === row.oid) {
                    reArr = [reArr[0], reArr[1] - 1];
                }
                let forCount = len - +rowIndex;
                for (let i = 1; i < forCount + 1; i++) {
                    if (rowIndex < len && this.orderItemData[rowIndex + i].oid === row.oid) {
                        reArr = [reArr[0] + 1, reArr[1]];
                    } else {
                        break;
                    }
                }
            }
            let flag = false;
            if (flag) ElMessage.info(len - rowIndex);
            return reArr;
        },
    }
}
</script>